<?php

/**
 * IndexController - The default controller class
 * 
 * @author
 * @version 
 */

require_once 'Zend/Controller/Action.php';

class Administrator_ExpressController extends Zend_Controller_Action 
{
	

	
	public function init(){
		
		$member=new CMember();
		
		if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName())){
			
			$this->_redirect(MY_URL.'/administrator-auth-login');
			
		}
		
		$memberArray = $member->getUserDetails(array('uid' => $_COOKIE[COOKIE_PRE.'uid']));
    	if($_COOKIE[COOKIE_PRE.'uid']=='1'){
				
		} else {
        	$strarray = explode(",", $memberArray[0]['menuflag']);
        	
        	if (!in_array('10', $strarray)) {
        		exit('no priviage');
        	}
		}
		
	}
	
	public function preDispatch()
	{
		
		$this->getHelper ('layout')->setLayout('framelayout');
		
		$this->view->addHelperPath(MY_ROOT.'/vhelpers');
		
		Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');
		
		//$this->getHelper('User')->getinfo($this->view,$this->_request->getModuleName(),$this->_request->getControllerName());
		
	}

	public function domesticAction(){
		
    	$page=$this->_request->getParam('page');
    	
		$express=new CExpress('domestic');
		
		$counts=$express->getAllExpressCounts();
		
    	Zend_Loader::loadClass("CFilter");
    	
    	$pageArray = CFilter::filterPage ( $page, $counts, 10 );
		
		$expressArray=$express->getAllExpress($pageArray['from'],10);
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPages( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/administrator-express-domestic?"); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
		
		$this->view->assign('expressArray',$expressArray);
		
		$shipFromArray=$express->getShipFrom('cn');
		
		$this->view->assign('shipFromArray',$shipFromArray);
		
		$weightArray=$express->getWeight();
		
		$this->view->assign('weightArray',$weightArray);
		
	}
	
	public function internationalAction(){
		
    	$page=$this->_request->getParam('page');
    	
		$express=new CExpress('international');
		
		$counts=$express->getAllExpressCounts();
		
    	Zend_Loader::loadClass("CFilter");
    	
    	$pageArray = CFilter::filterPage ( $page, $counts, 10 );
		
		$expressArray=$express->getAllExpress($pageArray['from'],10);
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPages( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/administrator-express-international?"); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
		
		$this->view->assign('expressArray',$expressArray);
		

		
		$weightArray=$express->getWeight();
		
		$this->view->assign('weightArray',$weightArray);
		
		
		$location=new CFenlei('location');
		
		
		    	
		$locationArray=$location->getFenleiByPid(0);
		
		$this->view->assign('locationArray',$locationArray);
		
		$expressCompany=new CExpressCompany();
		
		$companyArray=$expressCompany->getAllCompanies(0,0);
		
		$this->view->assign('companyArray',$companyArray);
		
	}
	
	public function addiAction(){
		
		$expressCompany=new CExpressCompany();
		
		$companyArray=$expressCompany->getAllCompanies(0,0);
		
		$this->view->assign('companyArray',$companyArray);
		
		$location=new CFenlei('location');
		    	
		$locationArray=$location->getFenleiByPid(0);
		
		$this->view->assign('locationArray',$locationArray);
		
		$locationArray=$location->getAllFenlei();
		
    	$selectString=$location->getAllSelect($locationArray,'235','locationFl.getChildFenlei(this);');
    	
    	$this->view->assign('selectString',$selectString);
		
	}
	
	public function doaddiAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$express=new CExpress('international');
		
		$thisArray=$this->_request->getParams();
    	
		$filters = array(
    		'*'   => 'StringTrim'
		);

		$validators = array(
		);
		
		$input = new Zend_Filter_Input($filters, $validators, $thisArray);
		
		$data=array(
					'from_station_id'=>$input->from_station_id,
					'to_station_id'=>$input->to_station_id,
					'carrier'=>$input->carrier,
					'type'=>$input->type,
					'weight'=>$input->weight,
					'price'=>$input->price,
					'first_weight'=>$input->first_weight,
					'addition_weight'=>$input->addition_weight,
					'days'=>$input->days,
					'en_description'=>$input->en_description,
					'cn_description'=>$input->cn_description,
					'is_recommended'=>$input->is_recommended,
					'add_time'=>time(),
					);
		
		$express->createExpress($data);
		
		//$session=new Zend_Session_Namespace('referPage');
		
		$this->view->showMsg('更新成功!','administrator-express-international');
		
	}
	
	public function editdAction(){
		
		$expressid=$this->_request->getParam('expressid');
		
		$express=new CExpress('domestic');
		
		$expressArray=$express->getDetail($expressid);
		
		$this->view->assign('expressArray',$expressArray);
		
		$session=new Zend_Session_Namespace('referPage');
    	
    	$session->prePage=$_SERVER['HTTP_REFERER'];
    	
    	
		
	}
	
	
	public function editiAction(){
		
		$expressid=$this->_request->getParam('expressid');
		
		$express=new CExpress('international');
		
		$expressArray=$express->getDetail($expressid);
		
		$this->view->assign('expressArray',$expressArray);
		
		$session=new Zend_Session_Namespace('referPage');
    	
    	$session->prePage=$_SERVER['HTTP_REFERER'];
    	
    	$location=new CFenlei('location');
		    	
		$locationArray=$location->getFenleiByPid(0);
		
		$this->view->assign('locationArray',$locationArray);
		
		$locationArray=$location->getAllFenlei();
		
    	$selectString=$location->getAllSelect($locationArray,$expressArray[0]['from_station_id'],'locationFl.getChildFenlei(this);');
    	
    	$this->view->assign('selectString',$selectString);
    	
    	$expressCompany=new CExpressCompany();
		
		$companyArray=$expressCompany->getAllCompanies(0,0);
		
		$this->view->assign('companyArray',$companyArray);
		
	}
	

	public function doeditiAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$expressid=$this->_request->getParam('expressid');
		
		$express=new CExpress('international');
		
		$thisArray=$this->_request->getParams();
    	
		$filters = array(
    		'*'   => 'StringTrim'
		);

		$validators = array(
		);
		
		$input = new Zend_Filter_Input($filters, $validators, $thisArray);
		
		$data=array(
					'from_station_id'=>$input->from_station_id,
					'to_station_id'=>$input->to_station_id,
					'carrier'=>$input->carrier,
					'type'=>$input->type,
					'weight'=>$input->weight,
					'price'=>$input->price,
					'first_weight'=>$input->first_weight,
					'addition_weight'=>$input->addition_weight,
					'days'=>$input->days,
					'en_description'=>$input->en_description,
					'cn_description'=>$input->cn_description,
					'is_recommended'=>$input->is_recommended,
					'add_time'=>time(),
					);
		
		$express->editExpress($expressid,$data);
		
		$session=new Zend_Session_Namespace('referPage');
		
		$this->view->showMsg('更新成功!',$session->prePage);
		
	}
	
	public function doeditdAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$expressid=$this->_request->getParam('expressid');
		
		$express=new CExpress('domestic');
		
		$thisArray=$this->_request->getParams();
    	
		$filters = array(
    		'*'   => 'StringTrim'
		);

		$validators = array(
		);
		
		$input = new Zend_Filter_Input($filters, $validators, $thisArray);
		
		$data=array(
					'from_station_cn'=>$input->from_station_cn,
					'from_station_en'=>$input->from_station_en,
					'to_station'=>$input->to_station,
					'carrier'=>$input->carrier,
					'type'=>$input->type,
					'weight'=>$input->weight,
					'price'=>$input->price,
					'first_weight'=>$input->first_weight,
					'addition_weight'=>$input->addition_weight,
					'days'=>$input->days,
					'fuel_surcharge'=>$input->fuel_surcharge,
					'en_description'=>$input->en_description,
					'cn_description'=>$input->cn_description,
					'is_recommended'=>$input->is_recommended,
					'add_time'=>time(),
					);
		
		$express->editExpress($expressid,$data);
		
		$session=new Zend_Session_Namespace('referPage');
		
		$this->view->showMsg('更新成功!',$session->prePage);
		
	}
	
	public function deliAction(){
		
		$expressid=$this->_request->getParam('expressid');
		
		$this->_helper->viewRenderer->setNoRender();
		
		$express=new CExpress('international');
		
		$express->delExpress(array($expressid));
		
		//$session=new Zend_Session_Namespace('referPage');
		
		$this->view->showMsg('删除成功!',$_SERVER['HTTP_REFERER']);
		
	}
	
	public function searchdAction(){
		
		$from=$this->_request->getParam('from');
		
		$weight=$this->_request->getParam('weight');
		
		$type=$this->_request->getParam('type');
		
		$this->view->assign('from',$from);
		
		$this->view->assign('weight',$weight);
		
		$this->view->assign('type',$type);
		
		$express=new CExpress('domestic');
		
		$express->setLang('cn');
		
		$express->setFrom($from);
		
		$express->setWeight($weight);
		
		$express->setType($type);
		
		$expressArray=$express->searchD();

		
		$page=$this->_request->getParam('page');
    	
    	$session=new Zend_Session_Namespace('page');
    	
    	$session->prePage=$page;
    	
		$express=new CExpress('international');
		
		$counts=count($expressArray);
		
    	Zend_Loader::loadClass("CFilter");
    	
    	$pageArray = CFilter::filterPage ( $page, $counts, 10 );

		$expressArray=array_slice($expressArray,$pageArray['from'],10);
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPages( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/administrator-express-searchd?from=".urlencode($from)."&weight=".urlencode($weight)."&type=$type"); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
		
		$this->view->assign('expressArray',$expressArray);
		
		$shipFromArray=$express->getShipFrom('cn');
		
		$this->view->assign('shipFromArray',$shipFromArray);
		
		$weightArray=$express->getWeight();
		
		$this->view->assign('weightArray',$weightArray);
		
		$this->render('domestic');
		
		
		
	}
    
	public function searchiAction(){
		
		$to_station_id=$this->_request->getParam('to_station_id');
		
		$weight=$this->_request->getParam('weight');
		
		$type=$this->_request->getParam('type');
		
		$carrier=$this->_request->getParam('carrier');
		
		$this->view->assign('to_station_id',$to_station_id);
		
		$this->view->assign('weight',$weight);
		
		$this->view->assign('type',$type);
		
		$this->view->assign('carrier',$carrier);
		
		$express=new CExpress('international');
		
		$express->setLang('en');
		
		$express->setTo($to_station_id);
		
		$express->setWeight($weight);
		
		$express->setType($type);
		
		$express->setCarrier($carrier);
		
		$expressArray=$express->searchI();

		
		$page=$this->_request->getParam('page');
    	
    	$session=new Zend_Session_Namespace('page');
    	
    	$session->prePage=$page;
    	
		$express=new CExpress('international');
		
		$counts=count($expressArray);
		
    	Zend_Loader::loadClass("CFilter");
    	
    	$pageArray = CFilter::filterPage ( $page, $counts, 10 );

		$expressArray=array_slice($expressArray,$pageArray['from'],10);
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPages( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/administrator-express-searchi?to_station_id=".$to_station_id."&weight=".urlencode($weight)."&type=$type&carrier=".$carrier); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
		
		$this->view->assign('expressArray',$expressArray);
		
		
		$weightArray=$express->getWeight();
		
		$this->view->assign('weightArray',$weightArray);
		
		
		$location=new CFenlei('location');
		    	
		$locationArray=$location->getFenleiByPid(0);
		
		$this->view->assign('locationArray',$locationArray);
		
		$expressCompany=new CExpressCompany();
		
		$companyArray=$expressCompany->getAllCompanies(0,0);
		
		$this->view->assign('companyArray',$companyArray);
		
		$this->render('international');
		
	}
	
	public function companyAction(){
		
		$page=$this->_request->getParam('page');
    	
		$company=new CExpressCompany();
		
    	Zend_Loader::loadClass("CFilter");
    	
    	$counts=$company->getAllCompanyCounts();
    	
    	$pageArray = CFilter::filterPage ( $page, $counts, 10 );
    	
    	$itemArray=$company->getAllCompanies($pageArray['from'],10);
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPages( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/administrator-express-company?"); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
		
		$this->view->assign('itemArray',$itemArray);	
		
	}
	
	public function addcompanyAction(){
		
		require_once (MY_ROOT."/fckeditor/fckeditor.php");
		
		$oFCKeditor_en = new FCKeditor('FCKeditor_en') ;
		
		$oFCKeditor_en->BasePath	= ROOT_PATH.'/fckeditor/' ;
		
		$oFCKeditor_en->Value		= '';
		
		$oFCKeditor_en->Height=400;
		
		$oFCKeditor_en->Width="98%";
		
		$this->view->assign('oFCKeditor_en',$oFCKeditor_en);
		
		$oFCKeditor_cn = new FCKeditor('FCKeditor_cn') ;
		
		$oFCKeditor_cn->BasePath	= ROOT_PATH.'/fckeditor/' ;
		
		$oFCKeditor_cn->Value		= '';
		
		$oFCKeditor_cn->Height=400;
		
		$oFCKeditor_cn->Width="98%";
		
		$this->view->assign('oFCKeditor_cn',$oFCKeditor_cn);
		
	}
	
	public function doaddcompanyAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$thisArray=$this->_request->getParams();
    	
		$filters = array(
    		'*'   => 'StringTrim'
		);

		$validators = array(
		);
		
		$input = new Zend_Filter_Input($filters, $validators, $thisArray);
		
		$company=new CExpressCompany();
		
		$data=array(
					'company_name'=>$input->company_name,
					'fuel_surcharge'=>$input->fuel_surcharge,
					'volume_param'=>$input->volume_param,
					'en_remark'=>htmlspecialchars_decode($input->FCKeditor_en),
					'cn_remark'=>htmlspecialchars_decode($input->FCKeditor_cn),
					'add_time'=>time()
					);
		
		$company->createCompany($data);
		
		$this->view->showMsg('新增成功！','administrator-express-company');
		
	}
	
	public function editcompanyAction(){
		
		$companyid=$this->_request->getParam('companyid');
		
		$expressCompany=new CExpressCompany();
		
		$companyArray=$expressCompany->getDetail($companyid);
		
		$this->view->assign('companyArray',$companyArray);
		
		require_once (MY_ROOT."/fckeditor/fckeditor.php");
		
		$oFCKeditor_en = new FCKeditor('FCKeditor_en') ;
		
		$oFCKeditor_en->BasePath	= ROOT_PATH.'/fckeditor/' ;
		
		$oFCKeditor_en->Value		= $companyArray[0]['en_remark'];
		
		$oFCKeditor_en->Height=400;
		
		$oFCKeditor_en->Width="98%";
		
		$this->view->assign('oFCKeditor_en',$oFCKeditor_en);
		
		$oFCKeditor_cn = new FCKeditor('FCKeditor_cn') ;
		
		$oFCKeditor_cn->BasePath	= ROOT_PATH.'/fckeditor/' ;
		
		$oFCKeditor_cn->Value		= $companyArray[0]['cn_remark'];
		
		$oFCKeditor_cn->Height=400;
		
		$oFCKeditor_cn->Width="98%";
		
		$this->view->assign('oFCKeditor_cn',$oFCKeditor_cn);
		
	}
	
	public function doeditcompanyAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$thisArray=$this->_request->getParams();
    	
		$companyid=$this->_request->getParam('companyid');
		
		$filters = array(
    		'*'   => 'StringTrim'
		);

		$validators = array(
		);
		
		$input = new Zend_Filter_Input($filters, $validators, $thisArray);
		
		$company=new CExpressCompany();
		
		$data=array(
					'company_name'=>$input->company_name,
					'fuel_surcharge'=>$input->fuel_surcharge,
					'volume_param'=>$input->volume_param,
					'en_remark'=>htmlspecialchars_decode($input->FCKeditor_en),
					'cn_remark'=>htmlspecialchars_decode($input->FCKeditor_cn),
					);
		
		$company->editCompany($companyid,$data);
		
		$this->view->showMsg('修改成功！','administrator-express-company');
		
	}
	
	public function delcompanyAction(){
		
		$this->_helper->viewRenderer->setNoRender();
		
		$companyid=$this->_request->getParam('companyid');
		
		$expressCompany=new CExpressCompany();
		
		try{
		
			$expressCompany->delCompanies(array($companyid));
			
			$this->view->showMsg('删除成功！','administrator-express-company');
			
		}catch (Exception $e){
			
			$this->view->showMsg('删除失败！','administrator-express-company');
			
		}
		
	}
	
	public function postAction(){
	
		//$this->_helper->viewRenderer->setNoRender();
		
		//$this->getHelper ('layout')->disableLayout ();
	
	}
    

    
}
